﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;


namespace Particles
{
    public class Particle
    {
        public Particle()
        {

        }

        PointF partVeloctiy;
        public System.Drawing.PointF PartVeloctiy
        {
            get { return partVeloctiy; }
            set { partVeloctiy = value; }
        }

        Rectangle particles;
        public System.Drawing.Rectangle Particles
        {
            get { return particles; }
            set { particles = value; }
        }
        PointF partPosition;
        public System.Drawing.PointF PartPosition
        {
            get { return partPosition; }
            set { partPosition = value; }
        }
        PointF endVeloctiy;
        public System.Drawing.PointF EndVeloctiy
        {
            get { return endVeloctiy; }
            set { endVeloctiy = value; }
        }

        int lifeSpan;
        public int LifeSpan
        {
            get { return lifeSpan; }
            set { lifeSpan = value; }
        }

        int currentlife;
        public int Currentlife
        {
            get { return currentlife; }
            set { currentlife = value; }
        }



        

        Point partScale;
        public System.Drawing.Point PartScale
        {
            get { return partScale; }
            set { partScale = value; }
        }

        Color partColor;
        public System.Drawing.Color PartColor
        {
            get { return partColor; }
            set { partColor = value; }
        }

        Color endPartColor;
        public System.Drawing.Color EndPartColor
        {
            get { return endPartColor; }
            set { endPartColor = value; }
        }

        Point endpartScale;
        public System.Drawing.Point EndpartScale
        {
            get { return endpartScale; }
            set { endpartScale = value; }
        }



        public void DrawParticles()
        {
            particles = new Rectangle((int)partPosition.X, (int)partPosition.Y, 5, 5);

            ManagedDirect3D.Instance.DrawRect(particles, 255, 255, 255);

            ManagedDirect3D.Instance.DrawText("hello world", 30, 30, 0, 255, 255);

        }

        public void ResetParticle(Emitter setpart)
        {
            Random velocityx = new Random(0);
            Random Velocityy = new Random(0);
            Random Positionx = new Random(0);
            Random Positiony = new Random(0);

            float fValX = velocityx.Next(-10, 10);
            float fVelY = Velocityy.Next(-10, 10);

            float posx = Positionx.Next(setpart.Emitrect.X, setpart.Emitrect.Width + setpart.Emitrect.X);
            float posy = Positiony.Next(setpart.Emitrect.Y, setpart.Emitrect.Height + setpart.Emitrect.Y);

            Color SetpartColor = new Color();

            PartVeloctiy = new PointF(fValX, fVelY);
            EndVeloctiy = new PointF(fValX, fVelY);
            LifeSpan = 1000;
            PartScale = new Point(1, 1);
            EndpartScale = new Point(5, 5);
            PartPosition = new PointF(posx, posy);


        }

        public void UpdateParticle(Emitter varemit)
        {
            // Check the curr Veloctiy if it is less than or greater than 
            // if less than subtract from it, if greater than add to it

            for (int x = 0; x < varemit.LiveParticles.Count; x++)
            {
                varemit.LiveParticles[x].currentlife++;

                varemit.LiveParticles[x].partPosition.X = varemit.LiveParticles[x].PartPosition.X + varemit.LiveParticles[x].partVeloctiy.X;
                varemit.LiveParticles[x].partPosition.Y = varemit.LiveParticles[x].PartPosition.Y + varemit.LiveParticles[x].partVeloctiy.Y;

                if (varemit.LiveParticles[x].currentlife > varemit.LiveParticles[x].lifeSpan)
                {
                    varemit.LiveParticles.Remove(this);
                    varemit.DeadParticles.Add(this);
                }

            }
        }
    }
}
